package com.op.studyingliteapp.database.dao;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.database.Cursor;

import com.op.studyingliteapp.bean.BaseBean;
import com.op.studyingliteapp.bean.ResourceBean;
import com.op.studyingliteapp.bean.UserBean;
import com.op.studyingliteapp.database.table.ResourceTable;
import com.op.studyingliteapp.database.table.UserTable;
import com.op.util.StringUtils;

/**
 * @author handsome
 * @version 创建时间：2015年7月25日 下午8:39:59 类说明
 */
public class ResourceDao extends AbstractDao {

	public ResourceDao(Context context, String userId) {
		super(context, userId);
		this.tb = ResourceTable.TABLE_COURSE_RESOURCE;
	}

	/**
	 * 通过课程ID来获得该课程所有通知
	 */
	public List<ResourceBean> getResourceByCourseId(String courseId) {
		List<ResourceBean> resourceList = new ArrayList<ResourceBean>();
		Cursor cursor = db.query(this.tb, ResourceTable.PROJECTION, ResourceTable.COLUMN_COURSE_ID + "=" + StringUtils.wrapQuote(courseId), null, null, null, null);
		while (cursor.moveToNext()) {

		}
		return resourceList;
	}

	/**
	 * 辅助类，用于生成实例
	 */
	public ResourceBean makeResourceNotifBeanByCursor(Cursor cursor) {
		ResourceBean resourceBean = new ResourceBean();

		resourceBean.setId(cursor.getString(cursor.getColumnIndex(ResourceTable.COLUMN_ID)));
		resourceBean.setCreateTime(cursor.getString(cursor.getColumnIndex(ResourceTable.COLUMN_CREATE_TIME)));
		resourceBean.setUpdateTime(cursor.getString(cursor.getColumnIndex(ResourceTable.COLUMN_UPDATE_TIME)));
		resourceBean.setTitle(cursor.getString(cursor.getColumnIndex(ResourceTable.COLUMN_TITLE)));
		resourceBean.setCourseId(cursor.getString(cursor.getColumnIndex(ResourceTable.COLUMN_COURSE_ID)));
		resourceBean.setCourseName(cursor.getString(cursor.getColumnIndex(ResourceTable.COLUMN_COURSE_NAME)));
		// UserBean
		UserBean userBean = new UserBean();
		userBean.setId(cursor.getString(cursor.getColumnIndex(BaseBean.captureName(UserTable.TABLE_USER,UserTable.COLUMN_ID))));
		userBean.setName(cursor.getString(cursor.getColumnIndex(BaseBean.captureName(UserTable.TABLE_USER,UserTable.COLUMN_NAME))));
		userBean.setEmail(cursor.getString(cursor.getColumnIndex(BaseBean.captureName(UserTable.TABLE_USER,UserTable.COLUMN_EMAIL))));
		userBean.setImageUrl(cursor.getString(cursor.getColumnIndex(BaseBean.captureName(UserTable.TABLE_USER,UserTable.COLUMN_IMAGE_URL))));
		userBean.setNumber(cursor.getString(cursor.getColumnIndex(BaseBean.captureName(UserTable.TABLE_USER,UserTable.COLUMN_NUMBER))));
		userBean.setPhone(cursor.getString(cursor.getColumnIndex(BaseBean.captureName(UserTable.TABLE_USER,UserTable.COLUMN_PHONE))));
		userBean.setIsUsing(cursor.getString(cursor.getColumnIndex(BaseBean.captureName(UserTable.TABLE_USER,UserTable.COLUMN_IS_USING))));
		userBean.setType(cursor.getString(cursor.getColumnIndex(BaseBean.captureName(UserTable.TABLE_USER,UserTable.COLUMN_TYPE))));
		resourceBean.setUserBean(userBean);
		return resourceBean;
	}

}
